/**
 * Created by MADinow on 25.10.2014.
 */

/* -----------------------------------------------------------
 LOADING UI MODULE
 ----------------------------------------------------------- */

define(['settings/variables', 'ui/madGenerator', 'jquery', 'jquery_ui'],
    function (Variables, Genny) {

        var _loadingPage = null ;
        var _loadingFadeInTime = 1000 ;
        var _loadingFadeOutTime = _loadingFadeInTime ;
        var _loadingFadeInDelay = 100 ;

        var _loadingText = 'connecting to ' + Variables.pageTitle.toLowerCase() + ' ' ;

        /**
         * initializes the loading screen
         * @param targetDom
         * @private
         */
        function _initLoadingScreen(targetDom) {
            _loadingPage = Genny.createDiv(targetDom, 'loadingPage', 'container-absolute page loadingPage', true);
            var loadingContainer = Genny.createDiv(_loadingPage, '', 'container-absolute loadingContainer', true);
            var loadingIcon = Genny.createDiv(loadingContainer, '', 'loadingIcon', true);
            var loadingAnimIcon = Genny.createIcon(loadingContainer, '', 'fa fa-spinner fa-2x fa-spin loadingAnimation', '', true);
            var loadingText = Genny.createDiv(loadingContainer, '', 'loadingText', true);
            loadingText.text(_loadingText);
        }

        /**
         * makes the loading screen fade in
         * @private
         */
        function _showLoadingScreen() {
            _loadingPage.fadeIn(_loadingFadeInTime);
        }

        /**
         * makes the loading screen fade out
         * @private
         */
        function _hideLoadingScreen(){
            _loadingPage.fadeOut(_loadingFadeOutTime);
        }

        /**
         * public interface
         */
        return {

            /* variables */
            loadingFadeInTime: _loadingFadeInTime,
            loadingFadeOutTime: _loadingFadeOutTime,
            loadingFadeInDelay: _loadingFadeInDelay,

            /* functions */
            initLoadingScreen: _initLoadingScreen,
            showLoadingScreen: _showLoadingScreen,
            hideLoadingScreen: _hideLoadingScreen

        }

    });